package com.blb.network;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * 发消息的线程
 */
public class WriteRunnable implements Runnable{

    private Socket socket = null;

    public WriteRunnable(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //创建输出流对象
        try(Scanner scanner = new Scanner(System.in);
            ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())){
            while(true){
                System.out.println("请输入你想说的话：");
                String message = scanner.nextLine();
                //发送给对方
                out.writeUTF(message);
                out.flush();
            }
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
}
